package com.coder520.sync_learning.demo.ThreadPool01;

import java.util.concurrent.TimeUnit;

public class ThreadPoolTest {

    public static void main(String[] args) throws InterruptedException {
        //定义线程 初始化为2，核心线程池为4，最大的线程池6 任务最多允许1000个任务
        final ThreadPool threadPool=new BasicThreadPool(2,6,4,1000);

        //定义20个任务并且提交给线程池
        for(int i=0;i<20;i++){
            threadPool.execute(()->{
                try {
                    TimeUnit.SECONDS.sleep(10);
                    System.out.println(Thread.currentThread().getName()+"线程正在运行");
                }catch (InterruptedException e){
                    e.printStackTrace();
                }
            });

            for (;;){
                //不断的输出线程池的信息
                System.out.println("当前的活动线程是："+threadPool.getActiveCount());
                System.out.println("当前的队列中的线程个数："+threadPool.getQueueSize());
                System.out.println("核心的线程："+threadPool.getCoreSize());
                System.out.println("最大的线程："+threadPool.getMaxSize());
                System.out.println("=========================");
                TimeUnit.SECONDS.sleep(5);
            }
        }
    }
}
